home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / NeoPersist 3.0.8 folder / Laughs / Source / CLaughsApp.cp next >
Encoding:
Text File  |  1994-10-13  |  5.0 KB  |  188 lines  |  [TEXT/MMCC]

  1. /*****
  2.  * CLaughsApp.cp
  3.  *
  4.  *    Implementation of a sample application full of laughter.
  5.  *
  6.  *    This sample app is derived from a contribution originally made
  7.  *    by Paul Gee (Thanks Paul!).
  8.  *
  9.  *  Copyright © 1994 NeoLogic Systems.  All rights reserved.
  10.  *
  11.  *    NOTE: This sample application uses the SIOUX serial i/o emulator for outputing
  12.  *    text using printf. There are a number of bugs in this mechanism which causes
  13.  *    rather unusual behavior.
  14.  *
  15.  *    While Laughs includes all the code necessary to open new and pre-existing files,
  16.  *    these SIOUX bugs do not allow Laughs' application menu to be accessible. The
  17.  *    application can not open pre-existing files as a result. The only possible work
  18.  *    around for this bug would be to comment out all printf statements and the call
  19.  *    to SendAEQuit in CLaughsDoc::newFile. The application will function correctly,
  20.  *    though no output will be written to the screen.
  21.  *
  22.  *    The window can't be moved on the screen. SIOUX ignores mouse clicks directed
  23.  *    to the window.
  24.  *
  25.  *    The Save menu item saves the text in the window NOT the NeoAccess database
  26.  *    that this application uses.
  27.  *
  28.  *****/
  29.  
  30. #include "NeoTypes.h"
  31. #include <stdio.h>
  32. #include "LGrowZone.h"
  33. #include "UMemoryMgr.h"
  34. #include "UPowerTools.h"
  35. #include CNeoDatabaseNativeH
  36. #include "CLaughsApp.h"
  37. #include "CLaughsDoc.h"
  38. #include "CPerson.h"
  39. #include CNeoMetaClassH
  40.  
  41. int main(void)
  42. {
  43.     CLaughsApp *    app;
  44.  
  45.     // PowerPlant asks that the following be done before an application is created.
  46.     InitializeHeap(1);
  47.     InitializeToolbox();
  48.     (void)new LGrowZone(20000);
  49.  
  50.     // Create an application object, run it, then delete it.
  51.     app = new CLaughsApp();
  52.     app->Run();
  53.     delete app;
  54.  
  55.     // Time to go home.
  56.     return 0;
  57. }
  58.  
  59. /***
  60.  * CLaughsApp
  61.  *
  62.  *    Initialize the application. Your initialization method should
  63.  *    at least call the inherited method. If your application class
  64.  *    defines its own instance variables or global variables, this
  65.  *    is a good place to initialize them.
  66.  *
  67.  ***/
  68. CLaughsApp::CLaughsApp(void)
  69.     : CNeoAppRoot(kLaughsSig, kLaughsFileType)
  70. {
  71.     CNeoMetaClass *        meta;
  72.  
  73.     // Note our file type so that we can be particular in the standard get file dialog.
  74.     FFileType = kLaughsFileType;
  75.  
  76.     // Let the games begin.
  77.     printf("Start Laughing...\n\n");
  78.  
  79.     // Add the application-specific metaclasses to the metaclass table.
  80.     meta = new CNeoMetaClass(kPersonID, kNeoPersistID, "\pCPerson");
  81.     meta = new CNeoMetaClass(kJokerID, kPersonID, "\pCJoker", CJoker::New);
  82.     meta = new CNeoMetaClass(kClownID, kPersonID, "\pCClown", CClown::New);
  83. }
  84.  
  85. /***
  86.  * createDocument
  87.  *
  88.  *    The user chose New from the File menu.
  89.  *    In this method, you need to create a document and send it
  90.  *    a NewFile() message.
  91.  *
  92.  ***/
  93. CNeoDoc *CLaughsApp::createDocument(void)
  94. {
  95.     CLaughsDoc *    document = nil;
  96.  
  97.     NEOTRY {
  98.         /*
  99.          * Create your document.
  100.          *
  101.          * The arguments indicate whether the document is...
  102.          *    printable (FALSE),
  103.          *    a new file (TRUE),
  104.          *    remote (FALSE).
  105.          */
  106.         document = new CLaughsDoc(FALSE, TRUE, FALSE);
  107.         NeoFailNil(document);
  108.         document->SetSuperCommander(this);
  109.  
  110.         // Call the document’s newFile method.
  111.         document->newDatabase();
  112.     }
  113.     NEOCATCH {
  114.         /*
  115.          * This exception handler gets executed if a failure occurred
  116.          * anywhere within the scope of the above NEOTRY block. Since
  117.          * this indicates that a new doc could not be created, we
  118.          * check if an object had been allocated and if it has, delete
  119.          * it. The exception will propagate up to the next exception
  120.          * handler, which displays an error alert.
  121.          */
  122.         if (document) {
  123.             delete document;
  124.             document = nil;
  125.         }
  126.     }
  127.     NEOENDTRY;
  128.  
  129.     return document;
  130. }
  131.  
  132. /***
  133.  * OpenDocument
  134.  *
  135.  *    The user chose Open… from the File menu.
  136.  *    In this method you need to create a document
  137.  *    and send it an openFile() message.
  138.  *
  139.  *    The aSpec is a good file specification record that contains
  140.  *    the name and vRefNum of the file the user chose to open.
  141.  *
  142.  ***/
  143.  
  144. void CLaughsApp::OpenDocument(FSSpec *aSpec)
  145. {
  146.     Boolean            remote        = FALSE;
  147.     CLaughsDoc *    document    = nil;
  148.  
  149.     VOLATILE(document);
  150.  
  151.     NEOTRY {
  152.         // Our parent will check to see if this is a document we have
  153.         // already opened. If we find the file already open by the app,
  154.         // then fDocument will refer to it. If the file is opened but
  155.         // not by this app, then the parent will signal a failure.
  156.         inherited::OpenDocument(aSpec);
  157.         if (fDocument)
  158.             return;
  159.  
  160.         // Create your document.
  161.         document = new CLaughsDoc(TRUE, FALSE, remote);
  162.         NeoFailNil(document);
  163.         document->SetSuperCommander(this);
  164.  
  165.         // Call the document's openFile method. The document will open
  166.         // a window, open the file specified in the file specification
  167.         // record, and display it in its window.
  168.         document->openFile(aSpec);
  169.  
  170.         delete document;
  171.         document = nil;
  172.     }
  173.     NEOCATCH {
  174.         /*
  175.          * This exception handler gets executed if a failure occurred
  176.          * anywhere within the scope of the NEOTRY block above. Since
  177.          * this indicates that the document could not be opened, we
  178.          * send it a unrefer message. The exception will propagate up to
  179.          * the event loop's exception handler, which handles displaying
  180.          * an error alert.
  181.          */
  182.         if (document)
  183.             delete document;
  184.     }
  185.     NEOENDTRY;
  186. }
  187.  
  188.